<?php
/**
 * Created by PhpStorm.
 * User: 63430
 * Date: 2018/11/15
 * Time: 16:24
 */

namespace app\user\model;

use think\Model;

class User extends Model
{
    protected $table = 'user';

    //定义好友关联
    public function friends(){
        return $this->hasMany('Friend','user_id','Id');
    }

    //定义课程表关联
    public function syllabus(){
        return $this->hasMany('Syllabus','userid','Id');
    }

    public function info($id){
        $result = $this->where('id',$id)->find();
        if ($result){
            return $result;
        }
    }

    public function showFriends($id){
        $data = $this->where('id',$id)->with('friends')->find();
        $friends = $data['friends'];
        return $friends;
    }

    public function showClasses($id){
        $data = $this->where('id',$id)->with('syllabus')->find();
        $classes = $data['syllabus'];
        return $classes;
    }
}